home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2006 December / PCWDEC06.iso / Software / Trial / Paint Shop Pro XI / Data1.cab / _094A3F15336446DBA640C8D1418AF4A6 < prev    next >
Encoding:
Text File  |  2006-08-04  |  5.2 KB  |  117 lines

  1. from PSPApp import *
  2. import PSPUtils
  3.  
  4. def ScriptProperties():
  5.     return {
  6.         'Author': u'Corel Corporation',
  7.         'Copyright': u'Copyright (c) 2002-2006 Corel Corporation. All rights reserved.',
  8.         'Description': "Split the current image to RGB, putting the separate channels back as layers in a layer group.",
  9.         'Host': u'Paint Shop Pro',
  10.         'Host Version': u'8.00'
  11.         }
  12.  
  13.  
  14. def Do(Environment):
  15.     if PSPUtils.RequireADoc( Environment ) == App.Constants.Boolean.false:
  16.         return
  17.     
  18.     # keep track of the doc we are starting with
  19.     TargetDoc = App.TargetDocument
  20.     
  21.     # start by splitting the current image.
  22.     App.Do( Environment, 'SplitToRGB', {
  23.             'GeneralSettings': {
  24.                 'ExecutionMode': App.Constants.ExecutionMode.Default, 
  25.                 'AutoActionMode': App.Constants.AutoActionMode.Match
  26.                 }
  27.             })
  28.  
  29.     # the split created 3 new documents and puts them at the end of the open list.
  30.     # make a three element list that we can reorder.  At this point we don't
  31.     # care about the contents, just that it has three elements
  32.     NewDocs = App.Documents[-3:]                # grab the last three docs
  33.           
  34.     # now loop over the three newest docs.
  35.     for ChannelDoc in App.Documents[-3:]:
  36.         Name = ChannelDoc.Title
  37.         if Name.find( PSPUtils.Blue ) != -1:
  38.           NewDocs[0] = ChannelDoc # make Blue first
  39.         elif Name.find( PSPUtils.Green ) != -1:
  40.           NewDocs[1] = ChannelDoc # make Green next
  41.         elif Name.find( PSPUtils.Red ) != -1:
  42.           NewDocs[2] = ChannelDoc # make Red last
  43.             
  44.     
  45.     FirstChannel = App.Constants.Boolean.true   # need special handling on the first one
  46.     
  47.     # We use explicit specification of which document to work on by adding a fourth
  48.     # parameter to the App.Do call.  For operations on one of the single channel
  49.     # images we use one of the saved docs.  For operations on the original doc we use
  50.     # the saved TargetDoc.
  51.     for Doc in NewDocs:  
  52.         # this shouldn't be necessary, but at the moment paste as new layer has a bug,
  53.         # so we promote manually.  This assumes the original image is RGB.
  54.         App.Do( Environment, 'IncreaseColorsTo16Million', {}, Doc )
  55.         
  56.         # copy it to the clipboard        
  57.         App.Do( Environment, 'Copy', {}, Doc )
  58.         
  59.         # paste it into the existing document - note the specification of target doc
  60.         App.Do( Environment, 'PasteAsNewLayer', {}, TargetDoc )
  61.  
  62.         # when we pasted it the layer came in as Raster Layer n, and we want to know what
  63.         # channel it represents, so pick up the image title and use that to determine
  64.         # the layer name.  Out of split to RGB the image will be named RedN, GreenN, and BlueN.
  65.         NewLayerName = Doc.Title
  66.         if NewLayerName.find( PSPUtils.Blue ) != -1:
  67.             NewLayerName = PSPUtils.BlueChannel
  68.         elif NewLayerName.find( PSPUtils.Green ) != -1:
  69.             NewLayerName = PSPUtils.GreenChannel
  70.         else:
  71.             NewLayerName = PSPUtils.RedChannel
  72.             
  73.         # now that we have the layer name, rename it
  74.         App.Do( Environment, 'LayerProperties', {
  75.                 'General': {
  76.                     'Name': NewLayerName, 
  77.                     }, 
  78.                 'GeneralSettings': {
  79.                     'ExecutionMode': App.Constants.ExecutionMode.Silent, 
  80.                     'AutoActionMode': App.Constants.AutoActionMode.Default
  81.                     }
  82.                 }, TargetDoc )
  83.         
  84.         # we want the channels to end up inside of a layer group, so after we
  85.         # paste the first channel in create a layer group to hold it, and then select
  86.         # the layer inside the group so subsequent creates go where we want them.
  87.         if FirstChannel == App.Constants.Boolean.true:
  88.             FirstChannel = App.Constants.Boolean.false
  89.  
  90.             # create the layer group
  91.             App.Do( Environment, 'NewLayerGroup', {
  92.                     'General': {
  93.                         'Name': PSPUtils.RGBChannels, 
  94.                         }, 
  95.                     'GeneralSettings': {
  96.                         'ExecutionMode': App.Constants.ExecutionMode.Silent, 
  97.                         'AutoActionMode': App.Constants.AutoActionMode.Match
  98.                         }
  99.                     }, TargetDoc )
  100.  
  101.             # select the member of the group rather than the group itself            
  102.             NewLayer = App.Do( Environment, 'SelectLayer', {
  103.                     'Path': (0,0,[1],App.Constants.Boolean.false), 
  104.                     'GeneralSettings': {
  105.                         'ExecutionMode': App.Constants.ExecutionMode.Silent, 
  106.                         'AutoActionMode': App.Constants.AutoActionMode.Default
  107.                         }
  108.                     }, TargetDoc)
  109.             
  110.         # do the close in silent mode since we don't want to save changes                
  111.         App.Do( Environment, 'FileClose', {
  112.                 'GeneralSettings': {
  113.                     'ExecutionMode': App.Constants.ExecutionMode.Silent, 
  114.                     'AutoActionMode': App.Constants.AutoActionMode.Match
  115.                     }
  116.                 }, Doc )
  117.